package com.example.utils;

import java.io.FileWriter;
import java.io.IOException;

/**临时的日志打印工具
 * @author LEI
 * Created by LEI on 2020/3/16.
 */
public class MyLog {
    private static String filePath = "D:\\log.txt";

    public synchronized static void log(String content) {

        String yyyymmddTime = DateUtils.getYYYYMMDDTime();
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(yyyymmddTime).append("  ->").append(content).append("\r\n");
        FileWriter fwriter = null;
        try {
            // true表示不覆盖原来的内容，而是加到文件的后面。若要覆盖原来的内容，直接省略这个参数就好
            fwriter = new FileWriter(filePath, true);
            fwriter.write(stringBuilder.toString());
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
                fwriter.flush();
                fwriter.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }

    }
}
